/**
 * HttpUtil.java
 * 作者：IccBoY
 * 2017年6月7日 创建文件
 */
package com.iccboy.cupload.util;

import javax.servlet.http.HttpServletRequest;

/**
 **************************************************
 * http工具
 * 
 * @version 1.0.0
 * @author  iccboy
 **************************************************
 */
public class HttpUtil {

	/**
	 * 获取客户端IP
	 * @return 客户端ip
	 * @since 1.0
	 * @author iccboy 2014-10-10 创建方法
	 */
	public static String getIpAddr(HttpServletRequest request) {
		try {
			String ip = request.getHeader("x-forwarded-for");
			if (ip == null || ip.length() == 0
					|| "unknown".equalsIgnoreCase(ip)) {
				ip = request.getHeader("Proxy-Client-IP");
			}
			if (ip == null || ip.length() == 0
					|| "unknown".equalsIgnoreCase(ip)) {
				ip = request.getHeader("WL-Proxy-Client-IP");
			}
			if (ip == null || ip.length() == 0
					|| "unknown".equalsIgnoreCase(ip)) {
				ip = request.getRemoteAddr();
			}
			return ip;
		} catch (RuntimeException e) {
			return null;
		}
	}
	
}
